home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoStyleStack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.8 KB  |  202 lines

  1. /* This file is part of the KDE project
  2.    Copyright (c) 2003 Lukas Tinkl <lukas@kde.org>
  3.    Copyright (c) 2003 David Faure <faure@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KOSTYLESTACK_H
  22. #define KOSTYLESTACK_H
  23.  
  24.  
  25. #include <qvaluelist.h>
  26. #include <qdom.h>
  27. #include <qvaluestack.h>
  28.  
  29. #include <kdemacros.h>
  30.  
  31. #include "koffice_export.h"
  32.  
  33. /**
  34.  *  @brief This class implements a stack for the different styles of an object.
  35.  *
  36.  *  There can be several styles that are valid for one object. For example
  37.  *  a textobject on a page has styles 'pr3' and 'P7' and a paragraph in
  38.  *  that textobject has styles 'P1' and 'T3'. And some styles even have
  39.  *  parent-styles...
  40.  *
  41.  *  If you want to know if there is, for example,  the attribute 'fo:font-family'
  42.  *  for this paragraph, you have to look into style 'T3', 'P1', 'P7' and 'pr3'.
  43.  *  When you find this attribute in one style you have to stop processing the list
  44.  *  and take the found attribute for this object.
  45.  *
  46.  *  This is what this class does. You can push styles on the stack while walking
  47.  *  through the xml-tree to your object and then ask the stack if any of the styles
  48.  *  provides a certain attribute. The stack will search from top to bottom, i.e.
  49.  *  in our example from 'T3' to 'pr3' and return the first occurrence of the wanted
  50.  *  attribute.
  51.  *
  52.  *  So this is some sort of inheritance where the styles on top of the stack overwrite
  53.  *  the same attribute of a lower style on the stack.
  54.  *
  55.  *  In general though, you wouldn't use push/pop directly, but KoOasisLoadingContext::fillStyleStack
  56.  *  or KoOasisLoadingContext::addStyles to automatically push a style and all its
  57.  *  parent styles onto the stack.
  58.  */
  59. class KOFFICECORE_EXPORT  KoStyleStack
  60. {
  61. public:
  62.     /**
  63.      * Create a OASIS style stack
  64.      */
  65.     KoStyleStack();
  66.     /**
  67.      * Create a style stack based on other namespaces than OASIS - used for OOo-1.1 import.
  68.      */
  69.     KoStyleStack( const char* styleNSURI, const char* foNSURI );
  70.     virtual ~KoStyleStack();
  71.  
  72.     /**
  73.      * Clears the complete stack.
  74.      */
  75.     void clear();
  76.  
  77.     /**
  78.      * Save the current state of the stack. Any items added between
  79.      * this call and its corresponding restore() will be removed when calling restore().
  80.      */
  81.     void save();
  82.  
  83.     /**
  84.      * Restore the stack to the state it was at the corresponding save() call.
  85.      */
  86.     void restore();
  87.  
  88.     /**
  89.      * Removes the style on top of the stack.
  90.      */
  91.     void pop();
  92.  
  93.     /**
  94.      * Pushes the new style onto the stack.
  95.      */
  96.     void push( const QDomElement& style );
  97.  
  98.     /**
  99.      * Check if any of the styles on the stack has an attribute called 'name'-'detail'
  100.      * where detail is e.g. left, right, top or bottom.
  101.      * This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.)
  102.      */
  103.     bool hasAttribute( const QString& name, const QString& detail = QString::null ) const KDE_DEPRECATED;
  104.  
  105.     /**
  106.      * Search for the attribute called 'name', starting on top of the stack,
  107.      * and return it.
  108.      */
  109.     QString attribute( const QString& name, const QString& detail = QString::null ) const KDE_DEPRECATED;
  110.  
  111.     /**
  112.      * Check if any of the styles on the stack has an attribute called 'name'-'detail'
  113.      * where detail is e.g. left, right, top or bottom.
  114.      * This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.)
  115.      */
  116.     bool hasAttributeNS( const char* nsURI, const char* localName, const char* detail = 0 ) const;
  117.  
  118.     /**
  119.      * Search for the attribute called 'name', starting on top of the stack,
  120.      * and return it.
  121.      */
  122.     QString attributeNS( const char* nsURI, const char* localName, const char* detail = 0 ) const;
  123.  
  124.     /**
  125.      * Check if any of the styles on the stack has a child node called 'name'.
  126.      */
  127.     bool hasChildNode( const QString & name ) const KDE_DEPRECATED;
  128.  
  129.     /**
  130.      * Search for a child node called 'name', starting on top of the stack,
  131.      * and return it.
  132.      */
  133.     QDomElement childNode( const QString & name ) const KDE_DEPRECATED;
  134.  
  135.     /**
  136.      * Check if any of the styles on the stack has a child element called 'localName' in the namespace 'nsURI'.
  137.      */
  138.     bool hasChildNodeNS( const char* nsURI, const char* localName ) const;
  139.  
  140.     /**
  141.      * Search for a child element which has a child element called 'localName'
  142.      * in the namespace 'nsURI' starting on top of the stack,
  143.      * and return it.
  144.      */
  145.     QDomElement childNodeNS( const char* nsURI, const char* localName ) const;
  146.  
  147.     /**
  148.      * Special case for the current font size, due to special handling of fo:font-size="115%".
  149.      */
  150.     double fontSize() const;
  151.  
  152.     /**
  153.      * Return the name of the style specified by the user,
  154.      * i.e. not an auto style.
  155.      * This is used to know e.g. which user-style is associated with the current paragraph.
  156.      * There could be none though.
  157.      */
  158.     QString userStyleName( const QString& family ) const;
  159.  
  160.     /**
  161.      * Return the display name of the style specified by the user,
  162.      * i.e. not an auto style
  163.      */
  164.     QString userStyleDisplayName( const QString& family ) const;
  165.  
  166.     /**
  167.      * Set the type of properties that will be looked for.
  168.      * For instance setTypeProperties("paragraph") will make hasAttribute() and attribute()
  169.      * look into "paragraph-properties".
  170.      * If @p typeProperties is 0, the stylestack is resetted to look for "properties"
  171.      * as it does by default.
  172.      */
  173.     void setTypeProperties( const char* typeProperties );
  174.  
  175. private:
  176.     bool isUserStyle( const QDomElement& e, const QString& family ) const;
  177.  
  178. private:
  179.     /// For save/restore: stack of "marks". Each mark is an index in m_stack.
  180.     QValueStack<int> m_marks;
  181.  
  182.     /**
  183.      * We use QValueList instead of QValueStack because we need access to all styles
  184.      * not only the top one.
  185.      */
  186.     QValueList<QDomElement> m_stack;
  187.  
  188.     QCString m_propertiesTagName;
  189.  
  190.     const char* m_styleNSURI;
  191.     const char* m_foNSURI;
  192.  
  193.     class KoStyleStackPrivate;
  194.     KoStyleStackPrivate *d;
  195.  
  196.     // forbidden
  197.     void operator=( const KoStyleStack& );
  198.     KoStyleStack( const KoStyleStack& );
  199. };
  200.  
  201. #endif /* KOSTYLESTACK_H */
  202.